<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>PhoneGap</title>
<link rel="stylesheet" href="master.css" type="text/css" >
<script type="text/javascript" charset="utf-8" src="cordova-1.7.0.js"></script>
<script type="text/javascript" charset="utf-8" src="dropboxplugin.js"></script>


<script type="text/javascript" charset="utf-8">
	document.addEventListener('deviceready', function() {
		var btn = document.getElementById("list-sdcard");
		btn.onclick = function() {

			window.plugins.dropboxplugin.listFolder("/sdcard", function(r) {
				printResult(r)
			}, function(e) {
				console.log(e)
			});
		}
		btn.disabled = false;
		
		var btn2 = document.getElementById("dropbox_login");
		btn2.onclick = function() {

			window.plugins.dropboxplugin.logIn(function(r) {
				
			}, function(e) {
				console.log(e)
			});
		}
		btn2.disabled = false;
		
	}, true);

	function printResult(fileInfo) {
		var innerHtmlText = getHtml(fileInfo);
		document.getElementById("result").innerHTML = innerHtmlText;
	}

	function getHtml(fileInfo) {
		var htmlText = "<ul><li>" + fileInfo.filename;
		if (fileInfo.children) {

			for ( var index = 0; index < fileInfo.children.length; index++) {
				htmlText = htmlText + getHtml(fileInfo.children[index]);
			}
		}
		htmlText = htmlText + "</li></ul>";
		return htmlText;
	}
</script>
</head>
<body>
	<input disabled id=dropbox_login type="button" value="Login" />
	<input disabled id="list-sdcard" type="button" value="List SDCard Contents" />
	
	
	<hr>

	<div id="result"></div>

	<hr>


</body>
</html>